package cn.pzaily.orange.manage.service.impl;

import cn.pzaily.orange.core.utils.page.MybatisPageHelper;
import cn.pzaily.orange.core.utils.page.PageRequest;
import cn.pzaily.orange.core.utils.page.PageResponse;
import cn.pzaily.orange.manage.dao.SysDictMapper;
import cn.pzaily.orange.manage.model.SysDict;
import cn.pzaily.orange.manage.model.SysDictExample;
import cn.pzaily.orange.manage.service.SysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PackageName: cn.pzaily.orange.manage.server.impl
 * @Description:
 * @Author: Pang
 * @Date: 2021-05-11 21:53
 */
@Service
public class SysDictServiceImpl implements SysDictService {

    @Autowired
    private SysDictMapper dictMapper;

    @Override
    public PageResponse findPage(PageRequest param) {
        Object label = param.getParam("label");
        if (null != label) {
            return MybatisPageHelper.selectPage(param, dictMapper, "selectPageByLabel", label);
        }
        return MybatisPageHelper.selectPage(param, dictMapper);
    }

    @Override
    public List<SysDict> findAll() {
        return dictMapper.selectByExample(null);
    }

    @Override
    public boolean save(SysDict data) {
        return dictMapper.insertSelective(data) == 1 ? true : false;
    }

    @Override
    public boolean modify(SysDict data) {
        return dictMapper.updateByPrimaryKeySelective(data) == 1 ? true : false;
    }

    @Override
    public SysDict findById(Long id) {
        return dictMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean removeByIds(List<Long> ids) {
        SysDictExample example = new SysDictExample();
        example.createCriteria().andIdIn(ids);
        int count = dictMapper.deleteByExample(example);
        return true;
    }

    @Override
    public List<SysDict> findByLable(String label) {
        return dictMapper.selectByLabel(label);
    }
}
